package com.education.user.mapper;

import com.education.user.pojo.SysMenu;
import com.education.user.pojo.SysMenuBig;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface SysMenuMapper extends Mapper<SysMenu> {


    @Select("select menu_id As id,menu_name As label from sys_menu\n" +
            "        where parent_id = #{parentId} and menu_name != ''  order by menu_id asc ")
    List<SysMenuBig> selectSysMenuByParentId(Integer parentId);


    @Select("select menu_id As id,menu_name As menuName,remark As permission,menu_type As menuType,is_show As isShow, icon from sys_menu where parent_id = #{parentId} and menu_id in (select menu_id from sys_role_menu where role_id = #{roleId}) ")
    List<SysMenu> selectSysMenuByPId(@Param("parentId") Integer parentId,@Param("roleId") Integer roleId);


    @Select({
            "<script>",
            "  select menu_id, menu_name, parent_id, order_num, url, menu_type, remark from sys_menu",
            "    <where>",
            "       <when test=\"menuIds != null \"> and menu_id in",
            "           <foreach item='id' collection='menuIds' separator=',' open='(' close=')' index=''>",
            "               #{id}",
            "           </foreach>",
            "       </when>",
            "    </where>",
            "</script>"
    })
    List<SysMenu> selectMenuList(@Param("menuIds") List<Integer> menuIds);


    @Select({
            "<script>",
            "  select menu_id As id, menu_name As menuName, parent_id As parentId, is_show As isShow, remark As permission ,menu_type As menuType, icon from sys_menu",
            "    <where>",
            "      parent_id = 0 ",
            "       <when test=\"menuIds != null \"> and menu_id in",
            "           <foreach item='id' collection='menuIds' separator=',' open='(' close=')' index=''>",
            "               #{id}",
            "           </foreach>",
            "       </when>",
            "    </where>",
            "    ORDER BY menu_id &lt;&gt;2183   ",
            "</script>"
    })
    List<SysMenu> selectMenuFirstList(@Param("menuIds")  List<Integer> menuIds);

    @Select({
            "<script>",
            "  select menu_id As id, menu_name As menuName, parent_id As parentId, is_show As isShow, remark As permission ,menu_type As menuType, icon from sys_menu",
            "    <where>",
            "       <when test=\"menuIds != null \"> and menu_id in",
            "           <foreach item='id' collection='menuIds' separator=',' open='(' close=')' index=''>",
            "               #{id}",
            "           </foreach>",
            "       </when>",
            "    </where>",
            "    ORDER BY menu_id &lt;&gt;2183   ",
            "</script>"
    })
    List<SysMenu> selectMenuFirstListTwo(@Param("menuIds")  List<Integer> menuIds);
}
